Make a test more resilient against the host system
authorAlex Crichton <alex@alexcrichton.com>
Wed, 24 Sep 2014 05:23:10 +0000 (22:23 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sat, 27 Sep 2014 04:16:31 +0000 (21:16 -0700)
If the host system had $HOME/.cargo/config which configured a user name/email
then this test would fail because those would be prioritized over $USER.

Closes #514

tests/test_cargo_new.rs

index 61b6936027a76936d55fd08072fcc1da567abf05..bd25aab41a52cbc5dab7b33d4a9926e9cc1aa091 100644 (file)
@@ -1,4 +1,4 @@
-use std::io::{fs, UserRWX, File};
+use std::io::{fs, UserRWX, File, TempDir};
 use std::io::fs::PathExtensions;
 use std::os;
 
@@ -101,10 +101,14 @@ test!(existing {
 })
 
 test!(finds_author_user {
-    assert_that(cargo_process("new").arg("foo").env("USER", Some("foo")),
+    // Use a temp dir to make sure we don't pick up .cargo/config somewhere in
+    // the hierarchy
+    let td = TempDir::new("cargo").unwrap();
+    assert_that(cargo_process("new").arg("foo").env("USER", Some("foo"))
+                                    .cwd(td.path().clone()),
                 execs().with_status(0));
 
-    let toml = paths::root().join("foo/Cargo.toml");
+    let toml = td.path().join("foo/Cargo.toml");
     let toml = File::open(&toml).read_to_string().assert();
     assert!(toml.as_slice().contains(r#"authors = ["foo"]"#));
 })